import { createRouter, createWebHistory } from "vue-router";
import type { App } from "vue";
import { setupRouterLoadingBar } from "./helper/routerLoadingBar";
import { staticRoutes } from "./staticRoutes";
import { setupDynamicRoute, loginToAddRoutes } from "./helper/dynamicRoute";
import { setupRouterPermission } from "./helper/routerPermission";

export const router = createRouter({
  history: createWebHistory(),
  routes: staticRoutes,
});

// 启动路由
export const setupRouter = (app: App<Element>) => {
  app.use(router);
  // 路由 loading bar
  setupRouterLoadingBar(router);
  // 动态路由
  setupDynamicRoute(router);
  // 路由权限
  setupRouterPermission(router);
};

export const setupAfterLoginDynamicRoute = () => {
  loginToAddRoutes(router);
};
